package com.mcy.springbatch.reader;


import com.mcy.springbatch.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.file.FlatFileItemReader;
import org.springframework.batch.item.file.MultiResourceItemReader;
import org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper;
import org.springframework.batch.item.file.mapping.DefaultLineMapper;
import org.springframework.batch.item.file.transform.DelimitedLineTokenizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * MultiResourceItemReader从多个文件读取普通格式数据
 */
@Slf4j
@Component
public class ReadUserDataMultiFlatFileItemReader extends MultiResourceItemReader {

    @Autowired
    private ReadUserDataFlatFileItemReader readUserDataFlatFileItemReader;

    /**
     * 不能在构造函数注入Delegate
     */
    @PostConstruct
    public void init() {
        setResources(new Resource[]{new FileSystemResource("/Users/calon/Desktop/userdata-1.txt"), new FileSystemResource("/Users/calon/Desktop/userdata-2.txt"), new FileSystemResource("/Users/calon/Desktop/userdata-3.txt")});
        setDelegate(readUserDataFlatFileItemReader);
    }

}
